package com.bage.finance.biz.service.impl;

import com.bage.common.service.TokenService;
import com.bage.common.util.DateUtil;
import com.bage.finance.biz.domain.VoucherSubjectAssistCalculateDetail;
import com.bage.finance.biz.dto.AdminDTO;
import com.bage.finance.biz.mapper.VoucherSubjectAssistCalculateDetailMapper;
import com.bage.finance.biz.service.VoucherSubjectAssistCalculateDetailService;
import com.bage.mybatis.help.MyBatisWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.bage.finance.biz.domain.VoucherSubjectAssistCalculateDetailField.*;

@Slf4j
@Service
@RequiredArgsConstructor
public class VoucherSubjectAssistCalculateDetailServiceImpl implements VoucherSubjectAssistCalculateDetailService {

    final TokenService<AdminDTO> tokenService;

    final VoucherSubjectAssistCalculateDetailMapper voucherSubjectAssistCalculateDetailMapper;

    @Override
    public boolean del(Long voucherId) {
        MyBatisWrapper<VoucherSubjectAssistCalculateDetail> wrapper = new MyBatisWrapper<>();
        wrapper.update(DelFlag, true)
                .update(MemberId, tokenService.getThreadLocalUserId())
                .update(UpdateTime, DateUtil.getSystemTime())
                .whereBuilder()
                .andEq(VoucherId, voucherId)
                .andEq(DelFlag, false);
        return true;
    }

    @Override
    public List<VoucherSubjectAssistCalculateDetail> listByVoucherId(Long voucherId) {
        MyBatisWrapper<VoucherSubjectAssistCalculateDetail> wrapper = new MyBatisWrapper<>();
        wrapper.select(Id, VoucherId, SubjectId, VoucherSubjectDetailId, AssistCalculateCateId, AssistCalculateId)
                .whereBuilder()
                .andEq(VoucherId, voucherId)
                .andEq(DelFlag, false);
        return voucherSubjectAssistCalculateDetailMapper.list(wrapper);
    }
}
